export const searchInterpolation = (array: number[], itemSearch: number): number | undefined => {
  let len = array.length;
  let index: number | undefined;

  let iStart = 0;
  let iEnd = len - 1;
  
  while(index === undefined && iStart < iEnd) {
    if (itemSearch < array[iStart] || itemSearch > array[iEnd]) {
      index = -1;
    }

    const alpha = (itemSearch - array[iStart]) / (array[iEnd] - array[iStart]);
    let half = Math.ceil(iStart + alpha * (iEnd - iStart));
    
    if (array[half] === itemSearch) {
      index = half;
    }
    if (array[half] < itemSearch) {
      iStart++;
    }
    if (array[half] > itemSearch) {
      iEnd--;
    }
  }
  
  return index ?? -1;
};
